package indi.defoliation.unknownrpg.api;

import java.util.Map;

import org.bukkit.entity.Entity;
import org.bukkit.entity.LivingEntity;
import org.bukkit.inventory.ItemStack;

import indi.defoliation.unknownrpg.api.attribute.Attribute;
import indi.defoliation.unknownrpg.api.attribute.AttributeBody;
import indi.defoliation.unknownrpg.api.attribute.NumberAttribute;

public interface RPGItemHelper {

	static RPGItem getEntityRPGItemsOnBody(Entity e,AttributeBody body) {
		return RPGItemFactory.getRPGItem(getItemStackOnBody(e,body));
	}
	static ItemStack getItemStackOnBody(Entity e,AttributeBody body) {
		if(!(e instanceof LivingEntity))return null;
		LivingEntity livingEntity = (LivingEntity)e;
		switch (body){
		case CHEST:
			return livingEntity.getEquipment().getChestplate();
		case FOOT:
			return livingEntity.getEquipment().getBoots();
		case HEAD:
			return livingEntity.getEquipment().getHelmet();
		case LEG:
			return livingEntity.getEquipment().getLeggings();
		case MAIN_HAND:
			return livingEntity.getEquipment().getItemInMainHand();
		case OFF_HAND:
			return livingEntity.getEquipment().getItemInOffHand();
		}
		return null;
	}
	static double getAllOfAttributeValueInBodyItems(Map<AttributeBody,? extends Attribute> map) {
		double value = 0;
		if(!map.values().iterator().hasNext()&&!(map.values().iterator().next() instanceof NumberAttribute)) return 0d;
		for(Attribute attValue : map.values()) {
			NumberAttribute<?> att = (NumberAttribute<?>) attValue;
			value += att.get().doubleValue();
		}
		return value;
	}
}
